package com.mingqijia.gassafety.console.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gap.basic.base.CommonResponse;
import com.gap.basic.exception.BizException;
import com.github.pagehelper.util.StringUtil;
import com.mingqijia.gassafety.authority.api.resp.config.DictionaryItemRespDTO;
import com.mingqijia.gassafety.db.entity.BusinessNotice;
import com.mingqijia.gassafety.db.entity.Dtu;
import com.mingqijia.gassafety.db.mapper.DtuMapper;
import com.mingqijia.gassafety.shared.constant.Constants;
import com.mingqijia.gassafety.shared.constant.OperateRecordEnum;
import com.mingqijia.gassafety.shared.constant.PageColumnConst;
import com.mingqijia.gassafety.shared.constant.PageListCode;
import com.mingqijia.gassafety.shared.dto.LogVO;
import com.mingqijia.gassafety.shared.user.UserBackend;
import com.mingqijia.gassafety.shared.utils.ApplicationUtils;
import com.mingqijia.gassafety.shared.utils.FileUtil;
import com.mingqijia.gassafety.shared.utils.HeaderUtil;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import com.mingqijia.gassafety.webserver.dto.CallTaskDTO;
import com.mingqijia.gassafety.webserver.request.*;
import com.mingqijia.gassafety.webserver.response.*;
import com.mingqijia.gassafety.webserver.service.*;
import com.mingqijia.gassafety.webserver.service.impl.XFCallServiceImpl;
import com.mingqijia.gassafety.webserver.service.workorder.mbp.MbpWorkOrderService;
import com.mingqijia.gassafety.shared.log.LogRecord;
import com.mingqijia.gassafety.webserver.utils.LogRecordAspect;
import com.mingqijia.gassafety.webserver.utils.LogUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.mingqijia.gassafety.shared.constant.Constants.*;
import static com.mingqijia.gassafety.shared.constant.OperateRecordEnum.*;
import static com.mingqijia.gassafety.shared.constant.PageColumnConst.*;


/**
 * <p>
 * 客户管理
 *
 * @author wanghai
 * @since 2022-02-23
 */

@Slf4j
@RestController
@RequestMapping("/business/v1/consumer")
@Api(tags = "客户管理")
public class ConsumerController {

    @Autowired
    XFCallServiceImpl xfCallService;

    @Autowired
    ConsumerService consumerService;

    @Autowired
    ConsumerServiceInfoService consumerServiceInfoService;

    @Autowired
    HeaderUtil headerUtil;

    @Autowired
    DtuMapper dMapper;
    @Autowired
    EquipmentService equipmentService;

    @Value(value = "${gassafety.installationPosition.checkSwitch}")
    private boolean checkSwitch = true;

    @Autowired
    CustomerSubsHistoryService customerSubsHistoryService;

    @Autowired
    MbpWorkOrderService mbpWorkOrderService;

    @Autowired
    XFCallServiceImpl callService;
    @Autowired
    OrganizationService organizationService;

    @Autowired
    FieldListShowService fieldListShowService;
    @Autowired
    ContactsService contactsService;
    
    @Autowired
    ConsumerLocationService consumerLocationService;

    @Autowired
    private BusinessNoticeService businessNoticeService;

    public static final String DIFFERENT_SERVICE_PACKAGE_MODE = "different_service_package_mode";

    @ApiOperation(value = "客户管理-客户列表")
    @PostMapping("/list")
    public CommonResponse<PageUtil<ConsumerResponse>> consumerList(@RequestBody ConsumerListRequest request) {
        request.setTemplateType(headerUtil.getTemplateType());
        PageUtil<ConsumerResponse> consumerList = null;
        if (BIND_CHANNEL_ASST == request.getTemplateType()) {
            consumerList = consumerService.consumerListAsst(request);
            consumerList.setColumns(PageColumnConst.add(asstConsumerListTitles, asstConsumerListIndices));

        } else if (BIND_CHANNEL_GAS == request.getTemplateType()) {
            List<FieldListShowResponse> responses = fieldListShowService.queryListShowByShowStatus(PageListCode.CUSTOMER_MANAGE.getCode(), ApplicationUtils.getWorkingUser().getUsername());
            List<String> fields = responses.stream().map(FieldListShowResponse::getFieldCode).collect(Collectors.toList());
            List<String> titles = responses.stream().map(FieldListShowResponse::getFieldName).collect(Collectors.toList());
            consumerList = consumerService.consumerList(request);
            consumerList.setColumns(PageColumnConst.add(titles.toArray(new String[]{}), fields.toArray(new String[]{})));
        }
        return CommonResponse.success(consumerList);
    }

    @ApiOperation("客户列表数量")
    @RequestMapping(value = "/list/condition", method = RequestMethod.POST)
    public CommonResponse<Map<String, Integer>> getAlertConditionList () {
        return CommonResponse.success(consumerService.getConditionList(),"success");
    }


    @ApiOperation(value = "客户详情")
    @GetMapping("/detail")
    public CommonResponse<ConsumerDetailResponse> consumerDetail(@RequestParam("consumerId") @NotNull String request) {
        return CommonResponse.success(consumerService.detail(request));
    }

    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_2)
    @ApiOperation(value = "新增客户信息")
    @PostMapping("/add")
    @Validated
    public CommonResponse<Object> addConsumer(@RequestBody @Valid ConsumerRequest request) {
        if (StringUtil.isNotEmpty(request.getName())) {
            if (!request.getName().matches("^[a-zA-Z0-9_\\u4e00-\\u9fa5]{2,32}$")) {
                throw new BizException("客户名必须符合 2-32位汉字、字母、数字、下划线.");
            }
        } else {
            request.setName("");
        }
        consumerService.addConsumer(request);

        return CommonResponse.success("success");
    }


    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_3, detail = "'【客户ID：' + #request + '】'", commonInfo = "#consumerService.getCustomInfo(#request)")
    @ApiOperation(value = "删除客户信息")
    @GetMapping("/delete")
    public CommonResponse<Object> deleteConsumer(@RequestParam(value = "consumerId") String request) {
        Integer templateType = headerUtil.getTemplateType();
        //分渠道
        if ( templateType.equals(BIND_CHANNEL_GAS)) {
            //渠道一, 判断当前客户是否有进行中工单
            mbpWorkOrderService.historyByConsumerId(request);
            consumerService.deleteConsumer(request);
        }else if(templateType.equals(BIND_CHANNEL_ASST)){
            consumerService.deleteConsumer(request);

        }
        return CommonResponse.success("");
    }

    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_4, detail = "'【客户ID：' + #consumerIdList + '】'", commonInfo = "#consumerService.getCustomInfoByIds(#consumerIdList)")
    @ApiOperation(value = "批量删除客户信息")
    @GetMapping("/batchDelete")
    public CommonResponse<Object> batchDeleteConsumer(@RequestParam("consumerIdList") List<String> consumerIdList) {
        consumerService.batchDeleteConsumer(consumerIdList);
        return CommonResponse.success("");
    }

    @LogRecord(operateType = OPERATE_TYPE_1, consumerId = "#request.id")
    @ApiOperation(value = "维护客户基本信息")
    @PostMapping("/edit")
    public CommonResponse<Object> editConsumer(@RequestBody @Valid ConsumerRequest request) {
        //与新增客户使用同一入参, 移动id校验位置
        if (request.getId() == null) {
            throw new BizException("参数id不能为空!");
        }
        if (StringUtil.isNotEmpty(request.getName())) {
            if (!request.getName().matches("^[a-zA-Z0-9_\\u4e00-\\u9fa5]{2,32}$")) {
                throw new BizException("客户名必须符合 2-32位汉字、字母、数字、下划线.");
            }
        }
        if (StringUtil.isNotEmpty(request.getSubsCode())){
            if (StringUtils.isEmpty(request.getOrgCode()))throw new BizException("户号对应组织机构不存在");
            VccUserRseponse vccUser = consumerService.getVccUser(request.getSubsCode(),"",request.getOrgCode());
            if (vccUser ==null ){
                throw new BizException("户号不存在");
            }
        }

        String message = consumerService.editConsumer(request);
        return CommonResponse.success(message);
    }

    @LogRecord(operateType = OPERATE_TYPE_81, consumerId = "#request.id")
    @ApiOperation(value = "更新燃气户信息")
    @PostMapping("/updateSubsInfo")
    public CommonResponse<Object> updateSubsInfo(@RequestBody @Valid ConsumerUpdateSubsInfoRequest request) {
        //与新增客户使用同一入参, 移动id校验位置
        if (request.getId() == null) {
            throw new BizException("参数id不能为空!");
        }
        String message = consumerService.updateSubsInfo(request);
        return CommonResponse.success(message);
    }


    @ApiOperation(value = "维护客户联系人信息")
    @PostMapping("/editContacts")
    @Validated
    public CommonResponse<List<ContactsResponse>> editContacts(@RequestBody @Valid ContactsEditRequest request) {
        consumerService.editContacts(request);
        List<ContactsResponse>  list=consumerService.contactsListByConsumer(request);
        return CommonResponse.success(list);
    }

    @LogRecord(operateType = OPERATE_TYPE_9, consumerId = "#request.consumerId")
    @ApiOperation(value = "客户绑定关联设备")
    @PostMapping("/bindingEquipment")
    public CommonResponse<Object> bindingEquipment(@RequestBody @Valid ConsumerBindingRequest request) {

        //企业级操作日志
        LogVO vo = new LogVO();
        StringBuilder stringBuilder = new StringBuilder();
        for (BindingPositionRequest bindingPositionRequest : request.getImeiList()) {
            stringBuilder.append(bindingPositionRequest.getImei()).append(";");
        }
        vo.setDetail("设备号：" + stringBuilder);
        LogRecordAspect.threadLocal.set(vo);

        if (checkSwitch) {
            for (BindingPositionRequest positionRequest : request.getImeiList()) {
                if (StringUtil.isEmpty(positionRequest.getInstallationPosition())) {
                    throw new BizException("请填写安装位置");
                }
            }
        }
        consumerService.bindingEquipment(request);
        return CommonResponse.success("success");

    }


    @LogRecord(operateType = OPERATE_TYPE_10, detail = "'【设备号：' + #request.imei + '】'", consumerId = "#request.consumerId")
    @ApiOperation(value = "客户解除关联设备")
    @PostMapping("/unbindingEquipment")
    public CommonResponse<Object> unbindEquipment(@RequestBody @Valid ConsumerunBindingRequest request) {
        request.setTemplateType(headerUtil.getTemplateType());
        request.setIsNotifyKitchen(true);

        Dtu dtu = equipmentService.getDeviceByImei(request.getImei(),ApplicationUtils.getWorkingSpId());
        if (dtu == null) return CommonResponse.failure("设备"+request.getImei()+"不存在！");
        if (Constants.ZJ_EQUIPMENT_FROM.equals(dtu.getEquipmentFrom())) {
            consumerService.unbindEquipment(request);
        } else {
            //分渠道做解绑逻辑
            if ( BIND_CHANNEL_GAS== request.getTemplateType()) {
                consumerService.unbindEquipment(request);
            }else if(BIND_CHANNEL_ASST == request.getTemplateType()){
                consumerService.unbindEquipmentAsst(request);
            }
        }
        return CommonResponse.success("success");
    }


    @ApiOperation(value = "通讯记录_设备基础信息")
    @GetMapping("/equipmentInfo")
    public CommonResponse<EquipmentInfoResponse> equipmentInfo(@RequestParam("imei") String imei) {
        return CommonResponse.success(consumerService.equipmentInfo(imei));
    }

    @ApiOperation(value = "通讯记录_控制器记录列表")
    @PostMapping("/dtuMeasure")
    public CommonResponse<PageUtil<DtuMeasureLogResponse>> dtuMeasureLog(@RequestBody @Valid EquipmentLogRequest request) {
        return CommonResponse.success(consumerService.dtuMeasureLog(request));
    }

    @ApiOperation(value = "通讯记录_探测器记录列表")
    @PostMapping("/detectorMeasureLog")
    public CommonResponse<PageUtil<DetectorMeasureLogResponse>> detectorMeasureLog(@RequestBody @Valid EquipmentLogRequest request) {
        return CommonResponse.success(consumerService.detectorMeasureLog(request));
    }

    @ApiOperation(value = "通讯记录_紫荆报警器接收器&电磁阀记录列表")
    @PostMapping("/receiverMeasure")
    public CommonResponse<PageUtil<ReceiverValveLogResponse>> receiverMeasureLog(@RequestBody @Valid EquipmentLogRequest request) {
        return CommonResponse.success(consumerService.receiverMeasureLog(request));
    }

    /**
     * 客户导入
     *
     * @return
     */
    @LogRecord(operateType = OPERATE_TYPE_38)
    @ApiOperation(value = "客户导入")
    @PostMapping("/import")
    public CommonResponse<Object> importData(@ApiParam(value = "file") MultipartFile file) {
//        return CommonResponse.success(consumerService.importData(file));
        return CommonResponse.success(consumerService.importDataSync(file));
    }

    @ApiOperation(value = "根据户号查询户表信息")
    @GetMapping("/getVccUser")
    public CommonResponse<Object> getVccUser(@ApiParam(value = "subsCode") @RequestParam(required = true) String subsCode,
                                             @RequestParam(required = false) String  orgCode) {
        VccUserRseponse vccUser = consumerService.getVccUser(subsCode,"",orgCode);
        if (vccUser == null){
            return CommonResponse.failure("户号不存在");
        }
        return CommonResponse.success(vccUser);
    }

    @ApiOperation(value = "户号更新户表信息")
    @GetMapping("/updateVccUser")
    public CommonResponse<String> updateVccUser(@ApiParam(value = "户号") @RequestParam String subsCode, @ApiParam(value = "客户id") @RequestParam String consumerId) {
        return CommonResponse.success(consumerService.updateVccUser(subsCode, consumerId));
    }

    @ApiOperation(value = "客户列表")
    @PostMapping("/custList")
    public CommonResponse<PageUtil<CustListResponse>> custList(@RequestBody CustListRequest request) {
        request.setTemplateType(headerUtil.getTemplateType());
        PageUtil<CustListResponse> pageUtil = null;

        String spId = ApplicationUtils.getWorkingSpId();
        List<FieldListShowResponse> responses = fieldListShowService.queryListShowByShowStatus(PageListCode.CUSTOMER_LIST.getCode(), ApplicationUtils.getWorkingUser().getUsername());
        List<String> fields = responses.stream().map(FieldListShowResponse::getFieldCode).collect(Collectors.toList());
        List<String> titles = responses.stream().map(FieldListShowResponse::getFieldName).collect(Collectors.toList());
        //模板一
        if ( BIND_CHANNEL_GAS== request.getTemplateType()) {
                pageUtil = consumerService.custList(request);
            //页面字段模板跟着请求头里的spId走
            pageUtil.setColumns(PageColumnConst.add(titles.toArray(new String[]{}), fields.toArray(new String[]{})));

        //模板二,时刻助手
        } else if (BIND_CHANNEL_ASST == request.getTemplateType()) {
            pageUtil = consumerService.custListAsst(request);
            pageUtil.setColumns(PageColumnConst.add(spId, asstCustListTitles, asstCustListIndices));
        }
        return CommonResponse.success(pageUtil);
    }

    @ApiOperation(value = "客户列表-右侧列表-模板二")
    @PostMapping("/custDetail")
    public CommonResponse<ConsumerDetailResponse> custDetail(@RequestBody @Valid CustDetailRequest request) {
        request.setTemplateType(headerUtil.getTemplateType());
        //查询设备来源
        QueryWrapper<Dtu> query = new QueryWrapper<>();
        query.lambda().or().eq(Dtu::getIsDeleted, 0)
                .eq(Dtu::getConsumerId, request.getConsumerId());
        List<Dtu> dtus = dMapper.selectList(query);
        Integer from = 0;
        if (!CollectionUtils.isEmpty(dtus)) {
            from = dtus.get(0).getEquipmentFrom();
        }
        //模板二 才会调用本接口
        if (BIND_CHANNEL_ASST !=request.getTemplateType()){
            throw new BizException("只允许模板二调用本接口");
        }
        ConsumerDetailResponse consumerDetailResponse =null;
        if (from==1){
            consumerDetailResponse = consumerService.detail(request.getConsumerId());
            ComsumerEquipmentRequest comsumerEquipmentRequest = new ComsumerEquipmentRequest();
            comsumerEquipmentRequest.setConsumerId(request.getConsumerId());
            consumerDetailResponse.setConsumerEquipmentResponseList(equipmentService.consumerEquipment(comsumerEquipmentRequest).getList());
        }else {
             consumerDetailResponse = consumerService.custDetail(request);
        }

        return CommonResponse.success(consumerDetailResponse);
    }


    @ApiOperation(value = "客户的用户绑定记录")
    @PostMapping("/customerSubsHistory")
    public CommonResponse<PageUtil<CustomerSubsHistoryResponse>> customerSubsHistory(@RequestBody @Valid CustomerSubsHistoryRequest request) {
        return CommonResponse.success(customerSubsHistoryService.getListBySubs(request));
    }





    @LogRecord(operateType = OPERATE_TYPE_39)
    @ApiOperation(value = "批量导入安装发起-客户管理-模板一")
    @PostMapping("/batchImport/workOrder")
    public CommonResponse<Object> batchImportWorkOrder(@ApiParam(value = "file") MultipartFile file) {
//        return CommonResponse.success(consumerService.batchImportWorkOrder(file));
        return CommonResponse.success(consumerService.batchImportWorkOrder(file));
    }

    @ApiOperation("上级组织 行业类型 汇总")
    @RequestMapping(value = "industryTypeList", method = RequestMethod.POST)
    public CommonResponse<Object> getIndustryTypeList( ){
        List<DictionaryItemRespDTO> list =  consumerService.getIndustryTypeList();
        return CommonResponse.success(list,"success");
    }




 /*   @ApiOperation(value = "外呼测试接口-创建app")
    @PostMapping("/appCreate")
    public CommonResponse<Object> appCreate( @RequestBody JSONObject json) {
        JSONObject jsonObject = xfCallService.appCreate("gassafety_call");
        return CommonResponse.success(jsonObject.toJSONString());
    }

    @ApiOperation(value = "外呼测试接口-创建任务池")
    @PostMapping("/tackPoolAdd")
    public CommonResponse<Object> tackPoolAdd( @RequestBody JSONObject json) {
        CallTaskDTO dto = new CallTaskDTO();
        dto.setAppId(json.getInteger("appId"));
        dto.setTaskCode(json.getString("taskCode"));
        dto.setTaskName(json.getString("taskName"));
        JSONObject jsonObject = xfCallService.tackPoolAdd(dto);
        return CommonResponse.success(jsonObject);
    }

    @ApiOperation(value = "外呼测试接口- 进行呼叫")
    @PostMapping("/callCreate")
    public CommonResponse<Object> callCreate( @RequestBody CallTaskDTO dto) {
        JSONObject jsonObject = xfCallService.callCreate(dto);
        return CommonResponse.success(jsonObject);
    }
*/

    @ApiOperation(value = "删除联系人")
    @GetMapping("/updateContacts")
    public CommonResponse<Object> callSearch(@RequestParam("id")Integer id) {
        contactsService.updateContacts(id);
        return CommonResponse.success(null);
    }

    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_60, consumerId = "#request.consumerId")
    @PostMapping("/editConsumerServiceInfo")
    @ApiOperation(value = "编辑客户服务信息")
    public CommonResponse<Object> editConsumerServiceInfo(@RequestBody @Valid SaveConsumerServiceInfoRequest request) {
        if (request.getId() == null) {
            throw new BizException("参数id不能为空!");
        }
        if (request.getEndDate().getTime() < request.getStartDate().getTime()) {
            throw new BizException("服务开始日期必须小于服务结束日期!");
        }
        //校验服务套餐是否为必填
        if (request.getPkgId() == null || request.getPkgId() == 0) {
            BusinessNotice noticeServiceByCode = businessNoticeService.getByCode(DIFFERENT_SERVICE_PACKAGE_MODE, ApplicationUtils.getWorkingSpId());
            if (noticeServiceByCode != null && "ON".equals(noticeServiceByCode.getParamValue())) {
                throw new BizException("客户套餐开启时为必填");
            }
        }
        String message = consumerServiceInfoService.editConsumerServiceInfo(request);
        return CommonResponse.success(message);
    }


    @PostMapping("/queryConsumerServiceInfoList")
    @ApiOperation(value = "查询客户服务信息")
    public CommonResponse<Object> queryConsumerServiceInfoList(@RequestBody ConsumerServiceInfoListRequest request) {
        return CommonResponse.success(consumerServiceInfoService.queryConsumerServiceInfoList(request));
    }

    @GetMapping("/queryConsumerServiceInfoTab")
    @ApiOperation(value = "查询客户服务信息tab标签信息")
    public CommonResponse<Object> queryConsumerServiceInfoTab() {
        return CommonResponse.success(consumerServiceInfoService.queryConsumerServiceInfoTab());
    }

    @PostMapping("/map/group")
    @ApiOperation(value = "地图分组组合数据")
    public CommonResponse<ConsumerMapGroupResponse> queryCustMapGroup(@RequestBody @Valid ConsumerMapGroupRequest request) {
        if( null!= request.getIsIncludeKitchen() && request.getIsIncludeKitchen() ){
            return CommonResponse.success(consumerLocationService.queryCustMapGroupListWithKitchen(request));
        }else{
            return CommonResponse.success(consumerLocationService.queryCustMapGroupList(request));
        }
        
    }

    @PostMapping("/map/list")
    @ApiOperation(value = "地图电子围栏数据")
    public CommonResponse<ConsumerMapResponse> queryCustMapList(@RequestBody @Valid ConsumerMapRequest request) {
        return CommonResponse.success(consumerLocationService.queryBoundaryCustList(request));
    }

    @PostMapping("/cust/list")
    @ApiOperation(value = "客户列表分页")
    public CommonResponse<PageUtil<CustListResponse>> queryCustList(@RequestBody CustListRequest request) {
        request.setTemplateType(headerUtil.getTemplateType());
        PageUtil<CustListResponse> pageUtil = null;

        String spId = ApplicationUtils.getWorkingSpId();
        List<FieldListShowResponse> responses = fieldListShowService.queryListShowByShowStatus(PageListCode.CUSTOMER_LIST.getCode(), ApplicationUtils.getWorkingUser().getUsername());
        List<String> fields = responses.stream().map(FieldListShowResponse::getFieldCode).collect(Collectors.toList());
        List<String> titles = responses.stream().map(FieldListShowResponse::getFieldName).collect(Collectors.toList());
        //模板一
        if ( BIND_CHANNEL_GAS== request.getTemplateType()) {
            pageUtil = consumerService.custListV2(request);
            //页面字段模板跟着请求头里的spId走
            pageUtil.setColumns(PageColumnConst.add(titles.toArray(new String[]{}), fields.toArray(new String[]{})));

            //模板二,时刻助手
        } else if (BIND_CHANNEL_ASST == request.getTemplateType()) {
            pageUtil = consumerService.custListAsst(request);
            pageUtil.setColumns(PageColumnConst.add(spId, asstCustListTitles, asstCustListIndices));
        }
        return CommonResponse.success(pageUtil);
    }

    @GetMapping("/selectAlertPosition")
    @ApiOperation(value = "是否报警，报警设备地址")
    public CommonResponse<List<Double>> selectAlertPosition() {
        return CommonResponse.success(consumerLocationService.selectAlertPosition());
    }

    @PostMapping("/queryBindDevice")
    @ApiOperation(value = "查询C端用户是否绑定设备")
    public CommonResponse<Object> queryBindDevice(@RequestBody ConsumerunBindDeviceRequest request) {
        return CommonResponse.success(consumerServiceInfoService.queryBindDevice(request));
    }
    @PostMapping("/map/listWithKitchen")
    @ApiOperation(value = "地图电子围栏数据,包含智慧厨房数据")
    public CommonResponse<ConsumerMapWitchKitchenResponse> queryCustMapListWithKitchen(@RequestBody @Valid ConsumerMapRequest request) {
        return CommonResponse.success(consumerLocationService.queryBoundaryCustListWithKitchen(request));
    }


    @GetMapping("/selectAlertPositionWithKitchen")
    @ApiOperation(value = "是否报警，报警设备地址,包含智慧厨房数据")
    public CommonResponse<List<Double>> selectAlertPositionWitchKitchen() {
        return CommonResponse.success(consumerLocationService.selectAlertPositionWithKitchen());
    }


    @ApiOperation(value = "批量查询客户详情")
    @PostMapping("/batchDetail")
    public CommonResponse<List<ConsumerResponse>> batchDetail(@RequestBody ConsumerDetailRequest request) {
        return CommonResponse.success(consumerService.batchDetail(request));
    }

    @PostMapping("/consumer/batchAllocationArea")
    @ApiOperation(value = "客户管理批量分配区域")
    public CommonResponse<Object> batchAllocationArea(@RequestBody ConsumerBatchAllocationAreaReq areaReq) {
        consumerLocationService.batchAllocationArea(areaReq);
        return CommonResponse.success(true);

    }

}
